<%@ page language="java"  pageEncoding="UTF-8"%>
<%@page import="com.fick.hibernate.dao.RoleDAO"%>
<%@page import="java.util.List"%>
<%@page import="com.fick.hibernate.model.Role"%>
<%@page import="com.fick.hibernate.model.Admin"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>角色管理</title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size: 12px;
}
.STYLE1 {font-size: 12px;}
.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;

}
a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}
a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.STYLE7 {font-size: 12px;}

</style>
<script type="text/javascript" src="js/check.js"></script>
<script type="text/javascript">
function checkForm(){
	if(trim(roleForm.roleName.value)==""){
		alert("请输入角色名称!");
		roleForm.roleName.focus();
		return false;
	}
	if(roleForm.roleOrder.value!=null && roleForm.roleOrder.value!="0" && !isInt(roleForm.roleOrder.value,"false")){
		alert("请输入正确的角色顺序!");
		roleForm.roleOrder.focus();
		return false;
	}
	return roleForm.submit();
}
</script>
</head>
<%
	//当前页面
	int currPage = 1;
	//总的页数
	int totalPage = 1;
	//一个页面可显示的记录数
	int pageSize = 20;
	//总共有的记录数
	int totalCount = 1;
	RoleDAO dao= new RoleDAO();
	List <Role> list=null ;
	//li = adminDao.findAll();
	//得到总的记录数
	Admin admin2 = (Admin)request.getSession().getAttribute("admin");
	if(admin2.getRole().getId() == 3)
	{
		totalCount = dao.getTotalCount(Role.class);
	}
	else
	{	
		totalCount = dao.count(Role.class,"where id != 3");
	}
	//得到总的页数
	if(totalCount%pageSize==0){
		totalPage = totalCount/pageSize;
	}else{
		totalPage = totalCount/pageSize+1;
	}
	//判断是否是传过来页数
	if(request.getParameter("currPage") != null){
	   currPage = Integer.parseInt(request.getParameter("currPage"));
	   if(currPage<1){
	     currPage=1;
	    }
	   if(currPage >totalPage){
	     currPage = totalPage;
	   }
	} 
	//得到记录数
	if(admin2.getRole().getId() == 3)
	{
		list = dao.findPageBySql(Role.class,currPage,pageSize,"order by roleOrder");
	}
	else
	{	
		list = dao.findPageBySql(Role.class,currPage,pageSize,"where id != 3 order by roleOrder");
	}
%>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="30"><img src="images/tab_03.gif" width="15" height="30" /></td>
        <td width="1101" background="images/tab_05.gif"><img src="images/311.gif" width="16" height="16" />
			<span class="STYLE4">角色管理页面</span></td>
        <td width="281" background="images/tab_05.gif">
        &nbsp;
        </td>
        <td width="14"><img src="images/tab_07.gif" width="14" height="30" /></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9" background="images/tab_12.gif">&nbsp;</td>
        <td bgcolor="#f3ffe3">
		<form action="role.do"  name="roleForm" method="post">
      <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">编号</div></td>
        <td width="54%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">角色名</div></td>
        <td width="8%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">排序</div></td>
        <td width="12%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">操作</div></td>
        </tr>
        <%
				if(list.size()>0){
					Role role;
				for(int i = 0 ; i < list.size(); i++){
						role = (Role)list.get(i);
			
		 %>
		
		<tr>
          <td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
		  <%=(currPage-1)*pageSize+i %></td>
          <td width="54%" height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px" class="STYLE1">
		  <%=role.getRoleName() %></td>
          <td width="8%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"><%=role.getRoleOrder() %></td>
          <td width="12%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
          <% if(role.getId() != 3 && role.getId() != 5){ %>
		  <a href="role_edit.jsp?id=<%=role.getId() %>">修改</a>
		  <a href="role.do?method=del&id=<%=role.getId() %>">删除</a>
		  <% } %>
		  </td>
        </tr>
       
	    <% }} %>
	    
		<tr>
        </tr>
		<tr>
		<input type="hidden" name="method" value="add">
          <td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF">
		 </td>
          <td width="54%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		 <input type="text" name="roleName"></td>
          <td width="8%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="hy_dsz"><input type="text" name="roleOrder"></td>
          <td width="12%" height="25" align="center" valign="middle" bgcolor="#FFFFFF">
		  <input type="button" onclick="checkForm()" value="添加"></td>
		</tr>	   
      </table>
      </form>
        
        </td>
        <td width="9" background="images/tab_16.gif">&nbsp;</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td height="29">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="29"><img src="images/tab_20.gif" width="15" height="29" /></td>
        <td background="images/tab_21.gif">
        <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="25" align="center" valign="middle" class="STYLE1">
		  共有［<%=totalCount %>］条 当前是第［<%=currPage %>/<%=totalPage %>］页 [<a href="role.jsp?currPage=1" class="page">首页</a>][<a href="role.jsp?currPage=<%=currPage-1 %>" class="page">上一页</a>][<a href="role.jsp?currPage=<%=currPage+1 %>" class="page">下一页</a>][<a href="role.jsp?currPage=<%=totalPage %>" class="page">尾页</a>]
		  到第
            <select name="select" onChange="gopage(this)">
			<%
				for(int i = 0;i<totalPage ; i++)
				{
					out.print("<option value='role.jsp?currPage="+(i+1)+"'>"+(i+1)+"</option>");
				}
			%>
			
            </select>
          页</td>
        </tr>
    </table>
        </td>
        <td width="14"><img src="images/tab_22.gif" width="14" height="29" /></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>


</html>
<script language="javascript">
 function gopage(selected)
 {
 	window.open(selected.value,"_self");
 }
 </script>
<script type="text/javascript">
<!--
var message = "<%=session.getAttribute("message")%>";
if(message!=null && message!="null" && message !=""){
   alert(message);
  }
//-->
</script>
<%
	session.removeAttribute("message");
%>